#include <bits/stdc++.h>
using namespace std;

int main() {
    int n, mn = INT_MAX;
    int arr[15][15];
    int dir[4][2] = {{0,  1},
                     {1,  0},
                     {0,  -1},
                     {-1, 0}};
    cin >> n;
    for (int i = 1; i <= n; ++i)
        for (int j = 1; j <= n; ++j) {
            cin >> arr[i][j];
            mn = min(mn, arr[i][j]);
        }

    --mn;
    int x = 1, y = 1, fx = 0, step = 0;
    while (step < n * n) {
        cout << arr[x][y] << ' ';
        arr[x][y] = mn;
        int dx = x + dir[fx][0];
        int dy = y + dir[fx][1];
        if (dx < 1 or dx > n or dy < 1 or dy > n or arr[dx][dy] == mn)
            (fx += 1) %= 4;
        x += dir[fx][0];
        y += dir[fx][1];
        ++step;
    }
    return 0;
}